package com.nil.codegen.utils;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.*;
import java.util.Properties;

public class Test {


    public static void main(String[] args) {

        String remoteJarUrl = "http://1.92.143.154:19000/test/temp/202511201501087fe1163f00926d4abd21c16218b94edc.jar";
        String className = "dm.jdbc.driver.DmDriver";
        String jdbcUrl = "jdbc:dm://10.1.86.82:32141/hb_basic_data";
        //String jdbcUrl = "jdbc:dm://dm_dw?dm_dw=(10.1.86.82:32141,10.1.86.83:32142)&loginMode=1&useUnicode=true&characterEncoding=utf8&schema=hb_basic_data";
        String username = "hb_basic_data";
        String password = "Gch_DzAtBXrTg5R";

        Properties props = new Properties();
        props.setProperty("user", username);
        props.setProperty("password", password);
        props.setProperty("characterEncoding", "utf-8");

        try {
            URL jarUrl = new URL(remoteJarUrl);
            URLClassLoader remoteClassLoader = new URLClassLoader(new URL[]{jarUrl}, ClassLoader.getSystemClassLoader());


            Class<?> driverClass = Class.forName(className, true, remoteClassLoader);
            java.sql.Driver driver = (Driver) driverClass.newInstance();
            Connection conn = driver.connect(jdbcUrl, props);
//            Connection conn = DriverManager.getConnection(jdbcUrl, props);
            System.out.println(conn);

            PreparedStatement ps = conn.prepareStatement("SELECT * from t_user limit 2");
            ResultSet resultSet = ps.executeQuery();
            while (resultSet.next()) {
                String col1 = resultSet.getString(2);
                System.out.println(col1);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }


}
